﻿Public Class DangKy

    Private Sub DangKy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim bang As DataTable = KiemTraNguoiDangNhap_BUS.LayThongTinTaiKhoan()
        DataGridView_thongtintaikhoan.DataSource = bang
    End Sub

    Private Sub Button_DangKy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_DangKy.Click
        Dim nguoidung As New KiemTraUsername_DTO()
        nguoidung.UserName = TxtDKUsername.Text
        nguoidung.PassWord = TxtDKPassword.Text
        If nguoidung.PassWord = "" And nguoidung.UserName = "" Then
            MessageBox.Show("Điền thông tin tài khoản mới")
        Else
            Dim trangthai As Boolean = KiemTraNguoiDangNhap_BUS.themtaikhoan(nguoidung)
            If trangthai = True Then
                Dim bang As DataTable = KiemTraNguoiDangNhap_BUS.LayThongTinTaiKhoan()
                DataGridView_thongtintaikhoan.DataSource = bang
            End If
        End If
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim user As String
        user = DataGridView_thongtintaikhoan.CurrentRow.Cells(0).FormattedValue.ToString()
        If MessageBox.Show("Bạn có chắc muốn xóa dòng này!", "xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then
            If user = "admin" Then
                MessageBox.Show("Không thể xóa tài khoản này")
            Else
                Dim i As Boolean = KiemTraNguoiDangNhap_BUS.Xoataikhoan(user)
                If i = True Then
                    Dim bang As DataTable = KiemTraNguoiDangNhap_BUS.LayThongTinTaiKhoan()
                    DataGridView_thongtintaikhoan.DataSource = bang
                End If

            End If
        End If
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Close()
    End Sub
End Class